#include <gtest/gtest-typed-test.h>
#include <gtest/gtest.h>

template <typename T>
T add(T a, T b) {
    return a + b;
}

template <typename T>
T sub(T a, T b) {
    return a - b;
}

// 1. 定义模板类
template <typename T>
class MathTest : public testing::Test {};

// 2. 定义参数化测试套件
TYPED_TEST_SUITE_P(MathTest);

// 3. 定义测试场景1：加法
TYPED_TEST_P(MathTest, AddTest) {
    TypeParam a = 1;
    TypeParam b = 2;
    TypeParam c = add(a, b);
    EXPECT_EQ(c, 3);
}

// 3. 定义测试场景2：减法
TYPED_TEST_P(MathTest, SubTest) {
    TypeParam a = 1;
    TypeParam b = 2;
    TypeParam c = sub(a, b);
    EXPECT_EQ(c, -1);
}

// 4. 注册测试
REGISTER_TYPED_TEST_SUITE_P(MathTest, AddTest, SubTest);

// 5. 实例化模板类
using MyTypes = testing::Types<int, double, float, long>;
INSTANTIATE_TYPED_TEST_SUITE_P(MyPrefix, MathTest, MyTypes);